{extend name="common:base"}
{block name="content"}
<fieldset class="layui-elem-field layui-field-title">
    <legend>{$title|default='用户管理'}</legend>
</fieldset>
<form action="" class="layui-form" method="post" enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">用户组名</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" placeholder="请输入用户组名" autocomplete="on" class="layui-input" {notempty name="oldData.title"} value="{$oldData.title}" {/notempty}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">组状态</label>
        <div class="layui-input-block">
            <input type="checkbox" {notempty name="oldData.status"}{if($oldData.status=='启用')}checked=""{/if}{/notempty} name="status" lay-skin="switch" lay-filter="switchTest" lay-text="激活|未激活" value="1">
        </div>
    </div>
    {:token()}
    <!--列出所有权限-->
    <fieldset class="layui-elem-field layui-field-title">
        <legend style="font-size: 15px;">权限设置</legend>
    </fieldset>
    {notempty name="rules"}
    {foreach $rules as $vo}
    <div class="layui-row" style="margin-left: 10px;">
        <input type="checkbox" name="rules[]" value="{$vo.id}" <?php if(!empty($oldData)) {if(array_key_exists($vo['id'],$oldData['rules'])) echo 'checked';}?>  title="{$vo.title}" lay-skin="primary">
        <br><br>
        <div class="layui-row" style="margin-left: 50px;">
            <!--如果为数组继续循环-->
            <?php if(is_array($vo['_data'])):?>
            {foreach $vo._data as $v2}
            <!--判断每一个权限id是否在rules中-->
                <input type="checkbox" name="rules[]" value="{$v2.id}" title="{$v2.title}"  lay-skin="primary" <?php if(!empty($oldData)) {if(array_key_exists($vo['id'],$oldData['rules'])) echo 'checked';}?>>
            {/foreach}
            <?php endif;?>
        </div>
        <br><br>
    </div>
    {/foreach}
    {/notempty}
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

{/block}
{block name="extend_js"}
<script>
    layui.use(['form','upload','layer'], function() {
        var $=layui.jquery
            ,form = layui.form
            ,upload=layui.upload
            ,layer=layui.layer;
        //普通图片上传
        var uploadInst=upload.render({
            elem:'#image'
            ,url:'{:url("api/Open/imgUpload")}' //文件上传接口
            ,ext:'jpg|png|gif'
//            ,area:'200px'
            ,drag:true
            //载入前配置
            ,before:function(){
                loading=layer.load(2,{shade:[0.2,'#000']});
            }
            ,done:function(res){
                layer.close(loading);
                layer.msg(res.msg);
                console.log(res);
                //上传完成显示地址到input
                $('input[name=image]').val(res.path);
                $('#img').attr('src',res.path);
            }
            ,error:function(){
//                请求异常回调
            }
        });
        //定义自定义验证规则
        form.verify({
           pass:[/(.+){6,12}$/,'密码必须6到12位']
            ,repass:function(value){
               var pass=$("input[name='password']").val();
               if(value !=pass){
                   return '两次密码不一致';
               }
            }
        });

//        form.render();
    });
</script>
{/block}